layui.use('form',function(){
    var form = layui.form,$ = layui.jquery;
    if(window!=top){
        parent.window.location.href =  "/login";
        return;
    }
    //监听提交
    form.on('submit(login)', function(data){
        var loading = layer.load(2, {
            shade: [0.2,'#000'] //0.2透明度的白色背景
        });
        var param = data.field;
        $.post('/login',param,function(res){
            layer.close(loading);
            if(res.code == 0){
                layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                    location.href = '/index';
                });
            }else{
                layer.msg(res.msg, {icon: 2, anim: 6, time: 1000});
                $('.kaptcha img').attr('src','/kaptcha?id='+Math.random());
            }
        });
        return false;
    });
});